package libra.forSentinel.openFeign;

import java.util.Map;

import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 配置OpenFeign.fallbackFactory属性的备选处理方案工厂类
 * 	此方法在Sentinel中只能处理程序异常，即@SentinelResource(fallback=xxx)。
 * 	如果是抛出的是BlockException（Sentinel相关流控异常），还是会尝试交由@SentinelResource(handler=xxx）处理
 */
@Component
public class FallBackFactoryImpl implements FallbackFactory<FeignClientInter> {

	@Override
	public FeignClientInter create(Throwable cause) {
		return new FeignClientInter() {
			@Override
			public Map<String, String> testFlowQps( Boolean exFlag ) {
				return fixFallback(this.getClass(), cause);
			}
			
			@Override
			public Map<String, String> testDegrade(Boolean exFlag, Integer exType) {
				return fixFallback(this.getClass(), cause);
			}
		};
	}

}
